package com.example.xmhds_1.mapper.userinfo;

import com.example.xmhds_1.entity.FriendList;
import org.apache.ibatis.annotations.*;

/**
 * 好友列表数据访问接口
 */
@Mapper
public interface FriendListMapper {

    /**
     * 获取用户的好友列表
     *
     * @param userId 用户ID
     * @return 好友列表信息
     */
    @Select("SELECT * FROM friend_list WHERE user_id = #{userId} AND deleted = 0")
    FriendList getByUserId(@Param("userId") String userId);

    /**
     * 创建好友列表
     *
     * @param friendList 好友列表信息
     * @return 影响的行数
     */
    @Insert("INSERT INTO friend_list (user_id, friends, deleted) " +
            "VALUES (#{userId}, #{friends}, #{deleted})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(FriendList friendList);

    /**
     * 更新好友列表
     *
     * @param friendList 好友列表信息
     * @return 影响的行数
     */
    @Update("UPDATE friend_list SET friends = #{friends} " +
            "WHERE id = #{id} AND deleted = 0")
    int updateById(FriendList friendList);

    /**
     * 逻辑删除好友列表
     *
     * @param id 列表ID
     * @return 影响的行数
     */
    @Update("UPDATE friend_list SET deleted = 1 WHERE id = #{id}")
    int deleteById(@Param("id") Long id);
}
